package ar.edu.sovietrussia.customcomponents.genericlistview;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

/**
 */
public class GenericProvider<T extends Serializable> extends SortableDataProvider<T> {

    private static final long serialVersionUID = 1L;

    private List<T> items;

    public GenericProvider(final List<T> itemsList) {
        super();
        this.items = itemsList;
    }

    @Override
    public Iterator<? extends T> iterator(final int first, final int count) {
        return this.getItems().subList(first, first + count).iterator();
    }

    @Override
    public int size() {
        return this.getItems().size();
    }

    @Override
    public IModel<T> model(final T object) {
        return Model.of(object);
    }

    public void setItems(final List<T> items) {
        this.items = items;
    }

    public List<T> getItems() {
        return this.items;
    }

}
